home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / wv2 / parser.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-12  |  4.7 KB  |  154 lines

  1. /* This file is part of the wvWare 2 project
  2.    Copyright (C) 2001-2003 Werner Trobin <trobin@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16.    Boston, MA 02111-1307, USA.
  17. */
  18.  
  19. #ifndef PARSER_H
  20. #define PARSER_H
  21.  
  22. #include "sharedptr.h"
  23. #include "global.h"
  24.  
  25. namespace wvWare
  26. {
  27.  
  28. // This ensures that we return the correct FIB :)
  29. // Note: The guy implementing Word95 support also has to return such
  30. // a Word97 FIB (as for most of the other important structures)!
  31. // We will create the conversion code with a script (at least those
  32. // parts of it which are easy to map)
  33. namespace Word97
  34. {
  35. struct FIB;
  36. struct DOP;
  37. struct SEP;
  38. struct FFN;
  39. struct STTBF;
  40. }
  41.  
  42. class InlineReplacementHandler;
  43. class SubDocumentHandler;
  44. class TableHandler;
  45. class TextHandler;
  46. class OLEStorage;
  47. class OLEStreamReader;
  48. class StyleSheet;
  49. class AssociatedStrings;
  50.  
  51. class WV2_DLLEXPORT Parser : public Shared
  52. {
  53. public:
  54.     /**
  55.      * This enum is needed to keep track of the parsing state. We e.g. have to
  56.      * handle footnote references differently while parsing footnotes. It's a bit
  57.      * hacky, but needed.
  58.      */
  59.     enum SubDocument { None, Main, Footnote, Header, Macro, Annotation, Endnote, TextBox, HeaderTextBox };
  60.  
  61.     /**
  62.      * Construct a parser. The reason that we get the "open" storage
  63.      * and the document reader passed (ugly :}) is that "someone" has
  64.      * to determine the nFib to select the proper parser... oh well
  65.      * At least we take ownership ;)
  66.      */
  67.     Parser( OLEStorage* storage, OLEStreamReader* wordDocument );
  68.     virtual ~Parser();  // Don't forget to close everything properly here
  69.  
  70.     /**
  71.      * Is everything allright?
  72.      */
  73.     bool isOk() const { return m_okay; }
  74.  
  75.     /**
  76.      * Invokes the parsing process.
  77.      */
  78.     virtual bool parse() = 0;
  79.  
  80.     /**
  81.      * Get the FIB (read only!)
  82.      */
  83.     virtual const Word97::FIB& fib() const = 0;
  84.     /**
  85.      * Get the DOP (read only!)
  86.      */
  87.     virtual const Word97::DOP& dop() const = 0;
  88.  
  89.     /**
  90.      * Get the font family name structure for a given ftc.
  91.      */
  92.     virtual const Word97::FFN& font( S16 ftc ) const = 0;
  93.  
  94.     /**
  95.      * Get the associated strings (author, title,...).
  96.      * Not cached, so don't use it like:
  97.      * parser->associatedStrings().author(); parser->associatedStrings().title()...
  98.      */
  99.     virtual AssociatedStrings associatedStrings() = 0;
  100.  
  101.     /**
  102.      * This stylesheet holds all the styles inside the Word file
  103.      */
  104.     virtual const StyleSheet& styleSheet() const = 0;
  105.  
  106.     /**
  107.      * The inline replacement handler is used to replace certain characters on the fly.
  108.      * We don't take ownership of the handler!
  109.      */
  110.     void setInlineReplacementHandler( InlineReplacementHandler* handler );
  111.     /**
  112.      * The sub-document handler gets all callbacks related to the document structure.
  113.      * We don't take ownership of the handler!
  114.      */
  115.     void setSubDocumentHandler( SubDocumentHandler* handler );
  116.     /**
  117.      * The table handler is used to tell the consumer about table structures.
  118.      * We don't take ownership of the handler!
  119.      */
  120.     void setTableHandler( TableHandler* handler );
  121.     /**
  122.      * The text handler is the main worker among all handlers. It's used to forward
  123.      * the formatted text to the document, make sure that it's fast.
  124.      * We don't take ownership of the handler!
  125.      */
  126.     void setTextHandler( TextHandler* handler );
  127.  
  128.     // Do we need public access to parts of the OLEStorage interface?
  129.     // If we add public accessors we should make m_storage private.
  130.  
  131. protected:
  132.     InlineReplacementHandler* m_inlineHandler;
  133.     SubDocumentHandler* m_subDocumentHandler;
  134.     TableHandler* m_tableHandler;
  135.     TextHandler* m_textHandler;
  136.     bool m_ourInlineHandler;
  137.     bool m_ourSubDocumentHandler;
  138.     bool m_ourTableHandler;
  139.     bool m_ourTextHandler;
  140.  
  141.     OLEStorage* m_storage;           // The storage representing the file
  142.     OLEStreamReader* m_wordDocument; // document stream ('WordDocument')
  143.  
  144.     bool m_okay;                     // Still allright?
  145.  
  146. private:
  147.     Parser( const Parser& rhs );
  148.     Parser& operator=( const Parser& rhs );
  149. };
  150.  
  151. } // namespace wvWare
  152.  
  153. #endif // PARSER_H
  154.